package tools

import (
	"errors"
	"testing"
)

func TestExitOnErr(t *testing.T) {
	mock := &ExitMock{}
	WithExit(t, mock)

	for _, test := range []struct {
		name     string
		input    error
		expected int
	}{
		{"no-err", nil, ExitOk},
		{"err", errors.New("issue"), ExitErr},
	} {
		t.Run(test.name, func(sub *testing.T) {
			ExitOnErr(test.input)

			result := mock.LastCode()
			if result != test.expected {
				sub.Errorf("expected: %d, got: %d", test.expected, result)
			}
		})
	}
}
